package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;

//JDBC中事务的隔离级别
public class JDBCDemo14 {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection()){
            //设置事务的隔离级别，通过connection来进行设置
            connection.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
            //将自动提交事务关闭
            String sql = "INSERT INTO userinfo (username,password,nickname,age) VALUES (?,?,?,?)";
            PreparedStatement ps = connection.prepareStatement(sql);
            ps.setString(1,"李太白");
            ps.setString(2,"234234");
            ps.setString(3,"小白白");
            ps.setInt(4,23);
            int i = ps.executeUpdate();
            //运用三目运算是比较高效的
            System.out.println(i>0? "成功": "不成功");
            connection.setAutoCommit(false);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
